﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Inference
{
    public partial class frmPreferences : Form
    {
        Settings settings = null;
        bool blockcbxAll = false;
        bool blockcbxuc = false;

        public frmPreferences(Settings settings)
        {
            InitializeComponent();
            this.settings = settings;
        }

        public List<ucHighlighterSettings> HighlighterSettingsControls
        {
            get
            {
                List<ucHighlighterSettings> res = new List<ucHighlighterSettings>();
                foreach (Control item in flpHighliters.Controls)
                {
                    try
                    {
                        res.Add((ucHighlighterSettings)item);
                    }
                    catch
                    {
                    }
                }
                return res;
            }
        }

        public List<ucHighlighterSettings> LinksSettingsControls
        {
            get
            {
                List<ucHighlighterSettings> res = new List<ucHighlighterSettings>();
                foreach (Control item in flpLinks.Controls)
                {
                    try
                    {
                        res.Add((ucHighlighterSettings)item);
                    }
                    catch
                    {
                    }
                }
                return res;
            }
        }

        private void frmPreferences_Load(object sender, EventArgs e)
        {
            flpLinks.Controls.Add(new ucHighlighterSettings(LinkTypes.is_a, settings, this));
            flpLinks.Controls.Add(new ucHighlighterSettings(LinkTypes.next, settings, this));
            flpLinks.Controls.Add(new ucHighlighterSettings(LinkTypes.sub, settings, this));

            foreach (Highlighter tvh in settings.TreeViewHighlighters)
            {
                flpHighliters.Controls.Add(new ucHighlighterSettings(tvh, this));
            }
            flpHighliters.Controls.SetChildIndex(pnlButtons, flpHighliters.Controls.Count);
        }

        private void cbxCheckAll_CheckedChanged(object sender, EventArgs e)
        {
            if (!blockcbxAll)
            {
                blockcbxuc = true;
                foreach (ucHighlighterSettings uchs in HighlighterSettingsControls)
                {
                    uchs.Checked = cbxCheckAll.Checked;
                }
                foreach (ucHighlighterSettings uchs in LinksSettingsControls)
                {
                    uchs.Checked = cbxCheckAll.Checked;
                }
                blockcbxuc = false;
            }
        }
        public void CheckCheckBoxes()
        {
            if (!blockcbxuc)
            {
                blockcbxAll = true;
                bool tmp = false;
                foreach (ucHighlighterSettings uchs in HighlighterSettingsControls)
                {
                    if (uchs.Checked)
                    {
                        tmp = true;
                        break;
                    }
                }
                if (!tmp)
                    foreach (ucHighlighterSettings uchs in LinksSettingsControls)
                    {
                        if (uchs.Checked)
                        {
                            tmp = true;
                            break;
                        }
                    }
                cbxCheckAll.Checked = tmp;
                blockcbxAll = false;
            }
        }

        private void btnLoadDefault_Click(object sender, EventArgs e)
        {
            ((ucHighlighterSettings)flpHighliters.Controls[0]).Checked = true;
            ((ucHighlighterSettings)flpHighliters.Controls[0]).ChosenColor = Color.Gray;
            
            ((ucHighlighterSettings)flpHighliters.Controls[1]).Checked = true;
            ((ucHighlighterSettings)flpHighliters.Controls[1]).ChosenColor = Color.LightPink;

            ((ucHighlighterSettings)flpHighliters.Controls[2]).Checked = false;
            ((ucHighlighterSettings)flpHighliters.Controls[2]).ChosenColor = Color.LightBlue;

            ((ucHighlighterSettings)flpHighliters.Controls[3]).Checked = true;
            ((ucHighlighterSettings)flpHighliters.Controls[3]).ChosenColor = Color.LightGreen;

            ((ucHighlighterSettings)flpHighliters.Controls[4]).Checked = false;
            ((ucHighlighterSettings)flpHighliters.Controls[4]).ChosenColor = Color.Red;

            ((ucHighlighterSettings)flpHighliters.Controls[5]).Checked = true;
            ((ucHighlighterSettings)flpHighliters.Controls[5]).ChosenColor = Color.Gold;

            ((ucHighlighterSettings)flpHighliters.Controls[6]).Checked = false;
            ((ucHighlighterSettings)flpHighliters.Controls[6]).ChosenColor = Color.Magenta;

            ((ucHighlighterSettings)flpHighliters.Controls[7]).Checked = false;
            ((ucHighlighterSettings)flpHighliters.Controls[7]).ChosenColor = Color.Orange;

            ((ucHighlighterSettings)flpHighliters.Controls[8]).Checked = false;
            ((ucHighlighterSettings)flpHighliters.Controls[8]).ChosenColor = Color.RosyBrown;

            ((ucHighlighterSettings)flpLinks.Controls[0]).Checked = true;
            ((ucHighlighterSettings)flpLinks.Controls[0]).ChosenColor = Color.Gray;
           
            ((ucHighlighterSettings)flpLinks.Controls[1]).Checked = true;
            ((ucHighlighterSettings)flpLinks.Controls[1]).ChosenColor = Color.Green;
            
            ((ucHighlighterSettings)flpLinks.Controls[2]).Checked = false;
            ((ucHighlighterSettings)flpLinks.Controls[2]).ChosenColor = Color.Magenta;
        }
    }
}
